
package at.fhj.ase.crypto.common.util;

/**
 * Class providing usable check-operations concerning network
 * 
 * @author sfe | www.fh-joanneum.at | Practical Aspects of Cryptography
 */
public final class NetworkUtil {

  private NetworkUtil() {
    throw new AssertionError("LogUtil: Util classes are not intended/allowed to be instantiated!");
  }

  /**
   * Checks whether the provided port number is valid by evaluating {@link #isPortNumberValid(int)}.
   * 
   * @param port the port number to be checked against validity
   * @return the port number if it is valid, otherwise throws {@link IllegalArgumentException}
   * @throws IllegalArgumentException if the provided port number is invalid
   */
  public static int checkPortNumber(int port) {
    if (!isPortNumberValid(port)) {
      throw new IllegalArgumentException("Valid port numbers must be higher than 1023!");
    }
    return port;
  }

  /**
   * @param port the port number to be checked against validity
   * @return <code>true</code> if the port number is greater than 1023, otherwise <code>false</code>
   */
  public static boolean isPortNumberValid(final int port) {
    return (port > 1023);
  }
}
